/**
 * 说明：
 * 创建人：pluto
 * 创建时间：2018/8/3
 */
var ComplainCtrl = function ($scope, ComplainService, $uibModal) {
    $scope.result = {};
    $scope.param = {pageNum: 1, pageSize: 10};

    var _loadData = function (param) {
        ComplainService.list(param).then(function (res) {
            console.log(res);
            $scope.result = res;
        });

    };
    _loadData($scope.param);
    /**
     * 处理提现申请
     * @param data
     */
    $scope.toHandle=function (data) {
        var modalInstance = $uibModal.open({
            templateUrl: 'pages/cash/view/handle.html',
            controller: 'ComplainHandleCtrl',
            backdrop: "handle",
            size: 'md',
            resolve: {
                data: function () {
                    return data;
                }
            }
        });

        modalInstance.result.then(function (selectedItem) {
            $scope.param.pageNum = 1;
            _loadData($scope.param);
        }, function (aaa) {
        });
    };
    /**
     * 查看提现详情
     * @param data
     */
    $scope.toDetail = function (data) {
        var modalInstance = $uibModal.open({
            templateUrl: 'pages/cash/view/detail.html',
            controller: 'ComplainHandleCtrl',
            backdrop: "handle",
            size: 'md',
            resolve: {
                data: function () {
                    return data;
                }
            }
        });

        modalInstance.result.then(function (selectedItem) {
            $scope.param.pageNum = 1;
            _loadData($scope.param);
        }, function (aaa) {
        });
    };
    $scope.search=function () {
        $scope.param.pageNum = 1;
        _loadData($scope.param);
    }
};
var ComplainHandleCtrl = function ($scope, $uibModalInstance, data, ComplainService) {
    $scope.uploadUrl = BASE_URL+'v0/file/upload';
    $scope.wallet = angular.copy(data);
    $scope.files = [];
    $scope.handle = {id: data.id};
    $scope.doHandle = function () {
        var fileList = [];
        for (var i = 0; i < $scope.files.length; i++){
            fileList.push({fileUrl: $scope.files[i]});
        }
        $scope.handle.fileList = fileList;
        ComplainService.handle($scope.handle).then(function (res) {
            $uibModalInstance.close();
        }, function (error) {
            console.log(error);
        })
    };
    $scope.close = function () {
        $uibModalInstance.dismiss();
    }
};
angular.module('app.complain.controller',[])
    .controller("ComplainCtrl", ComplainCtrl)
    .controller("ComplainHandleCtrl", ComplainHandleCtrl);

